********************************************************************************
* Exporting table for multi-country COVID paper (SLE1 Sample)
* last updated: 2020-10-22
* Salim Benhachmi
********************************************************************************

clear all
use "$da/SLE1", clear

********************************************************************************

* SES Status
preserve
keep hhid hh_consumption
duplicates drop
sum hh_consumption, detail
gen higher_ses = (hh_consumption >= `r(p50)')
gen lower_ses = (hh_consumption < `r(p50)')
drop hh_consumption
tempfile ses
save `ses'
restore
merge m:1 hhid using `ses', nogen

gen full_sample = 1

********************************************************************************

* Missed or reduced meals
gen fd_ins = (reduce_male == 1 | reduce_female == 1 | reduce_boy == 1 | ///
	reduce_girl == 1 | post_skip == 1) if covid_sample == 1

keep hhid survey_round higher_ses lower_ses pre_empl post_empl mkts_clsd ///
	ngo_gov_sprt fd_ins hhsize pre_inc post_inc covid_sample full_sample ///
	skip_health

sort hhid survey_round

drop survey_round

collapse (max) full_sample higher_ses lower_ses pre_empl post_empl mkts_clsd ///
	ngo_gov_sprt fd_ins hhsize covid_sample skip_health (mean) pre_inc ///
	post_inc, by(hhid)

* Drop in employment
gen drop_empl = (pre_empl == 1 & post_empl == 0) if pre_empl != . & ///
	post_empl != . 

* Drop in income
gen drop_inc = (pre_inc > post_inc) if pre_inc != . & post_inc != . 

********************************************************************************

keep if covid_sample == 1

local subgroups higher_ses lower_ses full_sample
local indicators drop_empl drop_inc mkts_clsd skip_health fd_ins ///
	ngo_gov_sprt

foreach subgroup of local subgroups {
	
	foreach ind of local indicators {
			
		sum `ind' if `subgroup' == 1
		loc mean_`ind'_`subgroup'  : di %10.2fc r(mean)
	}
}

sum covid_sample if higher_ses == 1
loc mean_n_higher_ses :  di %10.0fc r(N)
sum covid_sample if lower_ses == 1
loc mean_n_lower_ses :  di %10.0fc r(N)
sum covid_sample if full_sample == 1
loc mean_n_full_sample :  di %10.0fc r(N)


clear
set obs 3

local indicators drop_empl drop_inc mkts_clsd skip_health fd_ins ///
	ngo_gov_sprt n

foreach ind of local indicators {	
	gen mean_`ind' = ""
}

foreach ind of local indicators {	
	replace mean_`ind' = "`mean_`ind'_full_sample'" in 1
}

foreach ind of local indicators {	
	replace mean_`ind' = "`mean_`ind'_lower_ses'" in 2
}

foreach ind of local indicators {	
	replace mean_`ind' = "`mean_`ind'_higher_ses'" in 3
}

order mean_drop_inc mean_drop_empl mean_mkts_clsd mean_skip_health ///
	mean_fd_ins mean_ngo_gov_sprt mean_n

export excel using "$dtab/Main Table.xlsx", sheetmodify cell(B56)

********************************************************************************
